<template>
  <div>
    <div class="in_header">
      <el-form ref="form" :model="invocqdata" :inline="true">
        <!-- <el-form-item label="申请单号">
          <el-input v-model="invocqdata.apply_no" @click.stop.native style="width: 200px" placeholder="请输入" />
        </el-form-item> -->
        <el-form-item label="关联对象类型">
          <el-select
            v-model="invocqdata.relation_type"
            filterable
            placeholder="请选择"
            style="width: 200px"
          >
            <el-option
              v-for="item in categoryList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联对象">
          <el-select
            v-model="invocqdata.relation_id"
            filterable
            placeholder="请选择"
            style="width: 200px"
          >
            <el-option
              v-for="item in relevanceObj"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="报销主体">
          <el-select v-model="invocqdata.company_invoice_body_id" filterable placeholder="请选择" style="width: 200px">
            <el-option v-for="item in InvoiceBookList" :key="item.id" :label="item.invoice_body_name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建人">
          <el-select v-model="invocqdata.creator_id" filterable placeholder="请选择" style="width: 200px">
            <el-option v-for="item in staffData" :key="item.id" :label="item.username" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间">

          <el-date-picker @click.stop.native v-model="invocqdata.allTime" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" style="width: 300px" size="mini" value-format="timestamp" @change="handleDateChange" :default-time="['00:00:00', '23:59:59']" />

        </el-form-item> -->
        <el-form-item size="mini">
          <el-button
            type="primary"
            @click.stop.native
            icon="el-icon-search"
            @click="handleSearch"
            data-tracker="P54-1"
            >查询</el-button
          >
          <el-button
            type="primary"
            @click.stop.native
            plain
            icon="el-icon-refresh"
            @click="handleReset"
            data-tracker="P54-2"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- <div class="in_middle">
      <span v-if="invoice_body_belong == 0">
        <el-button data-tracker="P54-3"  type="primary" plain @click="reimbureadd()">新增</el-button>
        <el-button data-tracker="P54-5"  type="primary" plain @click="reimburedelet()">删除</el-button>
      </span>
      <span v-else-if="invoice_body_belong == 1">
      </span>
      <span v-else-if="invoice_body_belong == 2">
      
      </span>
      <span v-else-if="invoice_body_belong == 3">
        <el-button data-tracker="P54-10"  type="primary" plain @click="Cancellation()">取消核销</el-button>
      </span>
    </div> -->
    <div class="actions" >
      <div class="left">
        <span v-if="invoice_body_belong == 0">
          <el-button
            data-tracker="P54-3"
            type="primary"
            plain
            @click="reimbureadd()"
            >新增</el-button
          >
          <!-- <el-button data-tracker="P54-4"  type="primary" plain @click="reimbureedit(1)">编辑</el-button> -->
          <el-button
            data-tracker="P54-5"
            type="primary"
            plain
            @click="reimburedelet()"
            >删除</el-button
          >
          <!-- <el-button data-tracker="P54-6"  type="primary" plain @click="reimburereview()">发起审批</el-button> -->
        </span>
        <span v-else-if="invoice_body_belong == 1">
          <!-- <el-button data-tracker="P54-7"   type="primary" plain @click="approval()">撤回</el-button> -->
        </span>
        <span v-else-if="invoice_body_belong == 2"> </span>
        <span v-else-if="invoice_body_belong == 3">
          <el-button
            data-tracker="P54-10"
            type="primary"
            plain
            @click="Cancellation()"
            >取消核销</el-button
          >
        </span>
        <el-button
          @click="exportDerive()"
          plain
          type="primary"
          data-tracker="P49-4"
          style="margin-left: 10px"
          v-permission="'finance_customer_delete'"
          >导出</el-button
        >
      </div>
      <div class="right" style="display: flex">
        <el-button
          type="primary"
          size="mini"
          @click="resultClickFn"
          style="margin: 0px 10px 0px 0px"
          >重置
        </el-button>
        <SettinUp
          :settype="headerId"
          :objSettinUpdata="objSettinUp"
          :key="activeName"
        ></SettinUp>
      </div>
    </div>
    <!-- 表格 -->
    <div
      class="table"
      v-if="header_data_list.length > 0"
      :key="invoice_body_belong"

    >
      <TableHeader
        ref="TableHeaderList"
        :header_data_list="header_data_list"
        :HeaderData="HeaderData"
        :propMap="propMap"
        :redact="''"
        :particulars="''"
        :objheader="objheader"
        @orderIdNumsEvent="handleDeleteType"
        :operation_type="3"
      >
        <template #operation="{ scope }">
          <el-button
            data-tracker="P54-11"
            @click="reimbureedit(scope.row, 1)"
            type="text"
            size="small"
            v-if="invoice_body_belong == 0"
            >编辑</el-button
          >
          <el-button
            data-tracker="P54-11"
            @click="handleClick(scope.row)"
            type="text"
            size="small"
            >报销详情</el-button
          >
        </template>
      </TableHeader>
    </div>
    <div class="in_concent">
      <!-- <el-table :data="tableData" style="width: 100%" @selection-change="handleChange" border>
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column type="index" label="序号" width="50">
        </el-table-column>
        <el-table-column prop="apply_no" label="申请单号" width="180">
        </el-table-column>
        <el-table-column prop="relation_type" label="类别" width="180">
          <template slot-scope="scope">
            <span>{{scope.row.relation_type | capitalize }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="relation_name" label="关联名称 " width="180">
        </el-table-column>
        <el-table-column prop="branch_id_name" label="组织名称" width="180">
        </el-table-column>
        <el-table-column prop="status" label="状态" width="180">
          <template slot-scope="scope">
            <span>{{scope.row.status | statusOBj }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="apply_money" label="申请金额" width="180">
        </el-table-column>
        <el-table-column prop="actual_money" label="实际报销金额" width="180">
        </el-table-column>
        <el-table-column prop="is_used_petty_cash" label="是否使用备用金" width="180">
          <template slot-scope="scope">
          
            {{
              ["否", "是",][scope.row.is_used_petty_cash]
            }}
          </template>
        </el-table-column>
        </el-table-column>
        <el-table-column prop="charge_off_money" label="冲销备用金" width="180">
        </el-table-column>
        <el-table-column prop="petty_cash_id_name" label=" 备用金账户主体名称" width="180">
        </el-table-column>
        <el-table-column prop="receive_bank" label=" 行名" width="180">
        </el-table-column>
        <el-table-column prop="receive_bank_number" label=" 行号" width="180">
        </el-table-column>
        <el-table-column prop="payee" label="收款人" width="180">
        </el-table-column>
        <el-table-column prop="creator" label="创建人" width="180">
        </el-table-column>
        <el-table-column prop="create_time" label="创建时间" width="180">
          <template slot-scope="scope">
            <span v-time="scope.row.create_time"></span>
          </template>
        </el-table-column>
        <el-table-column prop="creator" label="操作人" width="180">
        </el-table-column>
        <el-table-column prop="update_time" label="操作时间" width="180">
          <template slot-scope="scope">
            <span v-time="scope.row.update_time"></span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="150">
          <template slot-scope="scope">
            <el-button data-tracker="P54-11" @click="reimbureedit(scope.row,1)" type="text" size="small" v-if="invoice_body_belong == 0">编辑</el-button>
            <el-button data-tracker="P54-11"  @click="handleClick(scope.row)" type="text" size="small">报销详情</el-button>
          </template>
        </el-table-column>
      </el-table> -->
      <div class="actions" style="width: 100%">
        <div class="left"></div>
        <div class="right">
          <el-pagination
            background
            small
            :current-page="paginations.pageIndex"
            :page-sizes="paginations.pageSizes"
            :page-size="paginations.pageSize"
            :layout="paginations.layout"
            :total="paginations.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <!-- 打款页面 -->
    <div>
      <el-dialog
        title="打款详情"
        :visible.sync="remittanceType"
        direction="rtl"
        width="800px"
      >
        <el-form
          ref="paymentList"
          :model="paymentList"
          :inline="true"
          label-width="120px"
        >
          <el-form-item label="申请单号:">
            <el-input
              v-model="paymentList.reimburse_no"
              @click.stop.native
              style="width: 200px"
              placeholder="请输入"
              :disabled="true"
            />
          </el-form-item>
          <el-form-item label="申请名称:">
            <el-input
              v-model="paymentList.apply_name"
              @click.stop.native
              style="width: 200px"
              placeholder="请输入"
              :disabled="true"
            />
          </el-form-item>
          <el-form-item label="实际报销金额:">
            <el-input
              v-model="paymentList.actual_reimburse_money"
              @click.stop.native
              style="width: 200px"
              placeholder="请输入"
              :disabled="true"
            />
          </el-form-item>
          <el-form-item label="收款人">
            <!-- <el-select v-model="paymentList.payee_id" filterable placeholder="请选择" style="width: 200px" :disabled="true">
              <el-option v-for="item in staffData" :key="item.id" :label="item.username" :value="item.id">
              </el-option>
            </el-select> -->
            <el-input
              v-model="paymentList.payee"
              @click.stop.native
              style="width: 200px"
              placeholder="请输入"
              :disabled="true"
            />
          </el-form-item>
          <el-form-item label="收款人银行">
            <el-input
              v-model="paymentList.open_bank_name"
              @click.stop.native
              style="width: 200px"
              placeholder="请输入"
              :disabled="true"
            />
          </el-form-item>
          <el-form-item label="收款人账号">
            <el-input
              v-model="paymentList.open_bank_account"
              @click.stop.native
              style="width: 200px"
              placeholder="请输入"
              :disabled="true"
            />
          </el-form-item>
        </el-form>
        <div style="margin: 0px 0px 10px 10px">
          <el-button
            type="primary"
            plain
            @click="paymentListadd()"
            v-if="disabledType != true"
            >新增</el-button
          >
          <el-button
            type="primary"
            plain
            @click="paymentListdelet()"
            v-if="disabledType != true"
            >删除</el-button
          >
        </div>
        <el-table
          :data="paymentList.payment_list"
          height="250"
          border
          style="width: 100%; margin: 0px 0px 0px 10px"
          @selection-change="tableRowClassName"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column prop="money" label="金额" width="140px">
            <template slot="header">
              <span style="color: red">*</span>
              <span>金额</span>
            </template>
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.money"
                :disabled="disabledType"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="create_time" label="时间">
            <template slot="header">
              <span style="color: red">*</span>
              <span>时间</span>
            </template>
            <template slot-scope="scope">
              <el-date-picker
                v-model="scope.row.create_time"
                type="datetime"
                value-format="timestamp"
                placeholder="选择日期时间"
                default-time="12:00:00"
                :default-value="new Date()"
                :disabled="disabledType"
              >
              </el-date-picker>
            </template>
          </el-table-column>
          <el-table-column prop="creator_id" label="操作人" width="150px">
            <template slot="header">
              <span style="color: red">*</span>
              <span>操作人</span>
            </template>
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.creator_id"
                filterable
                placeholder="请选择"
                :disabled="disabledType"
              >
                <el-option
                  v-for="item in staffData"
                  :key="item.id"
                  :label="item.username"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column property="remark" label="备注" width="130" key="11">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.remark"
                :disabled="disabledType"
              ></el-input>
            </template>
          </el-table-column>
        </el-table>
        <div style="margin: 10px 0px 0px 38%">
          <el-button type="primary" plain @click="remittanceType = false"
            >关闭</el-button
          >
          <el-button
            type="primary"
            plain
            @click="paymentadd()"
            v-if="disabledType != true"
            >保存</el-button
          >
          <el-button
            type="primary"
            plain
            @click="paymentwrite()"
            v-if="disabledType != true"
            >核销</el-button
          >
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import {
  carrierID,
  customerPeople,
  InvoiceBookoptions,
} from "../../../../api/information";
import { levelOptions } from "../../../../api/organization";
import {
  reimburseList,
  reimburseDelete,
  paymentDetail,
  paymentUpdate,
  paymentWriteoff,
  cancelPayment,
  reimburseReview,
  reimburseExport,
  reimburseCancelPayment,
  finance_reimburse_apply_list_export,
} from "../../../../api/finance";
import { timestamp10 } from "@/utils/mUtils";
import { AdminBox } from "@/api/Dataview";
import { Result } from "element-ui";
import TableHeader from "@/page/orderform/components/TableHeader/tableheader.vue";
import SettinUp from "@/page/orderform/components/settingUp/settingUp.vue";
export default {
  name: "reimburelment",
  components: { TableHeader, SettinUp },
  props: ["invoice_body_belong", "activeName"],
  data() {
    return {
      invocqdata: {
        relation_type: "", // 类别 0客户 1承运商 2渡石
        relation_id: "", // 关联id 客户id, 承运商id, 渡石公司id
        share_department_id: "", // 分摊部门id
        company_invoice_body_id: "", // 报销公司发票簿主体id
        status: "", // 状态 0待审批 1审批中 2审批通过 3已处理
        reimburse_no: "", // 申请单号
        payee_id: "", // 收款人id
        creator_id: "", // 创建人id
        start_time: "", // 开始时间
        end_time: "", // 结束时间
        page: 1,
        page_size: 10,
        inputValue: "",
        allTime: "",
        apply_no: "",
      },

      //搜索的名字
      categoryList: [
        {
          id: "0",
          name: "客户",
        },
        {
          id: "1",
          name: "承运商",
        },
        {
          id: "2",
          name: "渡石",
        },
      ],
      relevanceObj: [], //关联对象
      orginList: [], //组织
      InvoiceBookList: [], //发票主体
      staffData: [], //员工
      pickerOptions: {
        // 时间选择器的快选项
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      multipleSelection: [],
      paymentList: {
        actual_reimburse_money: "",
        apply_name: "",
        open_bank_account: "",
        open_bank_name: "",
        payee: "",
        payee_id: "",
        payment_list: [
          {
            id: "1",
            money: "", // 金额
            create_time: "", // 创建时间
            creator_id: "", // 创建人id
            remark: "", //备注
          },
        ],
        reimburse_id: "",
        reimburse_no: "",
      },

      checkedID: [],
      tableData: [],
      remittanceType: false,
      total: 0,
      currentPage4: 1,
      disabledType: false,
      checkedRows: [],
      searchParams: {},
      header_data_list: [],
      paginations: {
        pageIndex: 1, // 当前位于哪页
        pageSize: 20, // 1页显示多少条
        pageSizes: [10, 20, 50, 100], //每页显示多少条
        total: 200,
        layout: "total, sizes, prev, pager, next, jumper", // 翻页属性
      },
      propMap: {},
      obj_list: {},
      HeaderData: [],
      waybillIdNums: [],
      operation_type: 0,
      dynParams: {},
    };
  },
  filters: {
    capitalize: function (value) {
      if (value == "0") {
        return "客户";
      } else if (value == "1") {
        return "承运商";
      } else if (value == "2") {
        return "渡石";
      } else {
        return "";
      }
    },
    statusOBj: function (value) {
      if (value == "0") {
        return "待审批";
      } else if (value == "1") {
        return "审批中";
      } else if (value == "2") {
        return "审批通过";
      } else if (value == "3") {
        return "已处理";
      } else {
        return "";
      }
    },
  },
  watch: {
    "invocqdata.relation_type": {
      handler() {
        if (this.invocqdata.relation_type == 0) {
          this.invocqdata.relation_id = "";
          var param = {
            name: "",
            is_send: "1",
            is_receive: "",
          };
          customerPeople(param).then((res) => {
            this.relevanceObj = res.data;
          });
        } else if (this.invocqdata.relation_type == 1) {
          this.invocqdata.relation_id = "";
          var param = {
            name: "",
          };
          carrierID(param).then((res) => {
            this.relevanceObj = res.data;
          });
        } else if (this.invocqdata.relation_type == 2) {
          this.invocqdata.relation_id = "";
          var getItemUser = JSON.parse(localStorage.getItem("user"));
          this.relevanceObj = [
            {
              id: getItemUser.saas_company_id,
              name: getItemUser.branch_name,
            },
          ];
        }
      },
    },
  },
  computed: {
    headerId() {
      return "15";
    },
  },
  mounted() {
    this.handleSearch();
    this.levelOptionsobj();
    this.InvoiceBookoptionsObj();
    this.branchnameClickFn();
  },
  methods: {
    resultClickFn() {
      this.paginations.pageIndex = 1;
      this.paginations.pageSize = 20;
      this.$refs.TableHeaderList.childMethod();
    },
    objSettinUp() {
      this.getDataList();
    },
    levelOptionsobj() {
      var param = {
        pid: "1",
        name: "",
      };

      levelOptions(param).then((res) => {
        this.orginList = res.data;
      });
    },
    InvoiceBookoptionsObj() {
      var param = {
        body_belong: 0 + "", // 发票主体所属：0公司，1客户，2承运商
        belong_to_id: 0, // 发票主体所属id
        invoice_body_name: "", // 发票主体名
      };
      InvoiceBookoptions(param).then((res) => {
        if (res.code == "10000") {
          this.InvoiceBookList = res.data;
        }
      });
    },
    branchnameClickFn() {
      const data = {};
      AdminBox(data).then((res) => {
        if (res.code === 10000) {
          this.staffData = res.data;
        }
      });
    },
    reimbureadd() {
      // this.$router.push("reimburSement/reimburSementadd")
      this.$router.push({
        name: "reimburSementadd",
        query: { Type: 0, TageType: this.invoice_body_belong },
      });
    },
    reimbureedit(row, val) {
      // this.$router.push({ path: 'reimburSement/reimburSementadd', query: { id: this.multipleSelection[0].id } })
      // Type 2 是详情 1 是编辑 0 是 创建 TageType: 页面的切换 0 是待审批 1 是生啤中 2 是审批通过 3 是 审核记录
      this.$router.push({
        name: "reimburSementadd",
        query: { Type: val, id: row.id, TageType: this.invoice_body_belong },
      });
    },
    handleSearch() {
      this.getDataList();
    },
    handleDeleteType(ids, val) {
      this.handleChange(val);
    },
    getDataList(setHeader = true) {
     
      var param = {
        ...this.invocqdata,
        status_list: this.settingStatus(),
        relation_id: this.invocqdata.relation_id.toString(),
        share_department_id: this.invocqdata.share_department_id.toString(),
        company_invoice_body_id:
          this.invocqdata.company_invoice_body_id.toString(),
        payee_id: this.invocqdata.payee_id.toString(),
        creator_id: this.invocqdata.creator_id.toString(),
        page: this.paginations.pageIndex,
        page_size: this.paginations.pageSize,
        ...this.searchParams,
        header_id: this.headerId + "",
      };
      this.dynParams = param;
      reimburseList(param).then((res) => {
        this.tableData = res.data.data;
        this.paginations.total = res.data.pagination.total * 1;
        this.tableData.unshift({});
        this.header_data_list = this.tableData;
        if (setHeader) {
          this.HeaderData = res.data.item_list;
          this.Fntransformation(this.HeaderData);
        }
      });
    },
    objheader(obj) {
      this.paginations.pageIndex = 1;
      this.searchParams = obj;
      this.getDataList(false);
    },
    Fntransformation(obj) {
      const result = {};
      for (const prop in obj) {
        if (obj.hasOwnProperty(prop)) {
          if (obj[prop].send_name !== "") {
            result[obj[prop].name] = obj[prop].show_name;
          } else {
            result[obj[prop].name] = obj[prop].name;
          }
        }
      }
      this.propMap = result;
    },
    handleReset() {
      Object.assign(this.$data.invocqdata, this.$options.data().invocqdata);
      this.handleSearch();
    },
    clickRemittance() {
      this.disabledType = false;
      if (this.multipleSelection.length == 1) {
        this.remittanceType = true;
        var param = {
          id: this.multipleSelection[0].id,
        };
        paymentDetail(param).then((res) => {
          if (res.data.payment_list.length == 0) {
            this.paymentList = {
              ...res.data,
              payee_id: res.data.payee_id * 1,
              payment_list: [
                {
                  id: "1",
                  money: "", // 金额
                  create_time: "", // 创建时间
                  creator_id: JSON.parse(localStorage.getItem("user"))
                    .saas_company_id, // 创建人id
                },
              ],
            };
          } else {
            res.data.payment_list.forEach((item) => {
              (item.creator_id =
                item.creator_id * 1 == 0 ? "" : item.creator_id * 1),
                (item.create_time = item.create_time * 1000);
            });
            this.paymentList = {
              ...res.data,
              payee_id: res.data.payee_id * 1,
              payment_list: res.data.payment_list,
            };
          }
        });
      } else {
        this.open3("只能选择一个报销单", "warning");
      }
    },
    // 揽收时间变化
    handleDateChange(val) {
      if (val) {
        this.invocqdata.start_time = timestamp10(val[0]);
        this.invocqdata.end_time = timestamp10(val[1]);
      } else {
        this.invocqdata.start_time = "";
        this.invocqdata.end_time = "";
      }
    },
    handleChange(val) {
      this.checkedRows = val.map((item) => item.id);
      this.multipleSelection = val;
      this.sumOrder = val.length;
      if (val.length > 0) {
        for (var i = 0; i < this.multipleSelection.length; i++) {
          this.orderIdNums = this.multipleSelection.map((item) =>
            Number(item.id)
          );
          this.statusId = this.multipleSelection.map((item) => item.status);
        }
      } else {
        this.orderIdNums = [];
        this.statusId = [];
      }
    },
    reimburedelet() {
      if (this.multipleSelection.length == 1) {
        var param = {
          id: this.multipleSelection[0].id + "",
        };
        reimburseDelete(param).then((res) => {
          if (res.code == "10000") {
            this.open3("删除成功", "success");
            this.handleSearch();
          }
        });
      } else {
        this.open3("只能选择一个报销单", "warning");
      }
    },
    reimburereview() {
      var param = {
        id: this.multipleSelection[0].id + "",
      };
      reimburseReview(param).then((res) => {
        if (res.code == "10000") {
          this.open3("审核成功", "success");
          this.handleSearch();
        }
      });
    },
    tableRowClassName(val) {
      var deleid = [];
      for (var i = 0; i < val.length; i++) {
        deleid.push(val[i].id);
      }
      this.checkedID = deleid;
    },
    paymentListadd() {
      var id_length = this.paymentList.payment_list.length + 1;
      this.paymentList.payment_list.push({
        id: id_length,
        money: "", // 金额
        create_time: "", // 创建时间
        creator_id: JSON.parse(localStorage.getItem("user")).saas_company_id, // 创建人id
        remark: "", //备注
      });
    },
    paymentListdelet() {
      this.paymentList.payment_list.forEach((v, i) => {
        this.checkedID.forEach((val, index) => {
          if (val == v.id) {
            this.paymentList.payment_list.splice(i, 1);
          }
        });
      });
    },
    // 保存
    async paymentadd() {
      this.paymentList.payment_list.forEach((item) => {
        (item.create_time = timestamp10(item.create_time) + ""),
          (item.creator_id = item.creator_id + "");
      });
      var saveType = 3;
      this.paymentList.payment_list.forEach((item) => {
        if (item.money == "0.00" || item.money == " " || item.money == 0) {
          saveType = 1;
          // console.log(saveType, "saveType");
        } else if (item.create_time == "undefined") {
          saveType = 2;
          // console.log(saveType, "saveType");
        } else {
          saveType = 3;
          // console.log(saveType, "saveType");
        }
      });
      if (saveType == 3) {
        var param = {
          reimburse_id: this.multipleSelection[0].id, // 报销id
          payment_list: this.paymentList.payment_list,
        };
        await paymentUpdate(param).then((res) => {
          if (res.code == "10000") {
            this.open3("保存成功", "success");
            this.remittanceType = false;
            this.handleSearch();
          }
        });
      } else if (saveType == 1) {
        this.$message({
          message: "请输入金额",
          type: "warning",
        });
      } else if (saveType == 2) {
        this.$message({
          message: "请输入时间",
          type: "warning",
        });
      }
    },
    // 保存并核销
    paymentwrite() {
      this.paymentList.payment_list.forEach((item) => {
        (item.create_time = timestamp10(item.create_time) + ""),
          (item.creator_id = item.creator_id + "");
      });

      var dataList = {
        reimburse_id: this.multipleSelection[0].id, // 报销id
        payment_list: this.paymentList.payment_list,
      };
      paymentWriteoff(dataList).then((res) => {
        if (res.code == "10000") {
          this.open3("核销成功", "success");
          this.remittanceType = false;
          this.handleSearch();
        }
      });
    },
    // 取消核销
    Cancellation() {
      if (this.multipleSelection.length == 1) {
        var canceList = {
          id: this.multipleSelection[0].id,
        };
        cancelPayment(canceList).then((res) => {
          if (res.code == "10000") {
            this.open3("取消审核成功", "success");
            this.handleSearch();
          }
        });
      } else {
        this.open3("只能选择一个报销单", "warning");
      }
    },
    open3(message, type) {
      this.$message({
        message: message,
        type: type,
      });
    },
    handleSizeChange(val) {
      this.paginations.pageSize = val;
      this.handleSearch();
    },
    handleCurrentChange(val) {
      this.paginations.pageIndex = val;
      this.handleSearch();
    },
    clickDerive() {
      var param = {
        ...this.invocqdata,
        ids: this.checkedRows.map(Number),
        status: this.invoice_body_belong,
        relation_id: this.invocqdata.relation_id.toString(),
        share_department_id: this.invocqdata.share_department_id.toString(),
        company_invoice_body_id:
          this.invocqdata.company_invoice_body_id.toString(),
        payee_id: this.invocqdata.payee_id.toString(),
        creator_id: this.invocqdata.creator_id.toString(),
      };
      reimburseExport(param).then((res) => {
        this.reqUrl = "https://" + res.data.loaded_url;
        window.open(this.reqUrl);
      });
    },
    approval() {
      if (this.multipleSelection.length == 1) {
        var param = {
          id: this.multipleSelection[0].id,
        };
        reimburseCancelPayment(param).then((res) => {
          if (res.code == "10000") {
            this.open3("取消审批成功", "success");
            this.handleSearch();
          }
        });
      } else {
        this.open3("只能选择一个审批单", "warning");
      }
    },
    handleClick(row) {
      // this.$router.push({ path: 'reimburSement/reimburSementadd', query: { id: row.id , type:2} })
      this.$router.push({
        name: "reimburSementadd",
        query: { Type: 2, id: row.id, TageType: this.invoice_body_belong },
      });
    },
    detailsHandleClick(row) {
      this.multipleSelection = [row];
      this.clickRemittance();
      this.disabledType = true;
    },
    exportDerive() {
      var params = {
        ...this.invocqdata,
        status_list:this.settingStatus(),
        relation_id: this.invocqdata.relation_id.toString(),
        share_department_id: this.invocqdata.share_department_id.toString(),
        company_invoice_body_id:
          this.invocqdata.company_invoice_body_id.toString(),
        payee_id: this.invocqdata.payee_id.toString(),
        creator_id: this.invocqdata.creator_id.toString(),
        ...this.searchParams,
        header_id: this.headerId + "",
      };
      finance_reimburse_apply_list_export(params).then((res) => {
        this.reqUrl = "https://" + res.data.url;
        window.open(this.reqUrl);
      });
    },
    settingStatus() {
      // 0,4 是待审批的
      var invoice_status = []
      if(this.invoice_body_belong * 1 == 2 ) {
        invoice_status = [2, 3]
      }else if (this.invoice_body_belong * 1 == 0 ) {
        invoice_status = [0,4]
      } else {
        invoice_status =[ this.invoice_body_belong * 1]
      }
      return invoice_status
    }
  },
};
</script>
<style scoped lang="less">
/deep/.el-form-item--mini.el-form-item,
.el-form-item--small.el-form-item {
  margin-bottom: 10px;
}

/deep/ .in_header .el-form-item__label {
  padding: 0px 8px 0px 0px;
}

.in_middle {
  margin-bottom: 10px;
}

.in_concent {
  .in_concnet_left {
    width: 100%;
    margin: 10px 0px 0px 0px;
    display: flex;
    flex-direction: row-reverse;
  }
}
.actions {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  width: 100%;
  background-color: #fff;
  margin: 10px 10px 10px 0px;
}
</style>